﻿using LabManagement.Data.DataModel;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LabManagement.Data.DataUtilities
{
    public class LabsUtils:BaseDataUtils
    {
        public LabsUtils(DataManager bridge) : base(bridge) { }

        public IEnumerable<Lab> Labs(Guid? LabId = null, int? pageNo = null, int? pagesize = null)
        {
            var _labs = this.Bridge.DataFactory.Labs.OrderBy(l => l.CreationDate);
            if (LabId.HasValue)
            {
                _labs = this.Bridge.DataFactory.Labs.Where(l => l.LabId == LabId).OrderBy(c => c.CreationDate);
                return _labs;
            }
            return _labs;
        }

        public IEnumerable<LabCategoryModel> LabCategories(Guid? LabId = null)
        {
            var _labs = this.Bridge.DataFactory.Database.SqlQuery<LabCategoryModel>(@"select 
                T2.LabCategoryId
                ,T2.LabId
                ,T1.CategoryId
                ,T1.CategoryName
                ,IsNull(T2.Active,0) As Active                 
                from [Categories] T1
                left outer join LabCategories T2
                On T1.CategoryId=T2.CategoryId");          
            return _labs.ToList();
        }
    }
}
